package cdu.zch.healthcare;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

public class DoctorDetailsActivity extends AppCompatActivity {

    // 枚举每个页面医生的信息，各有五个信息
    private String[][] doctor_details1 =
            {
                    {"医生姓名：Ajit Saste", "医院地址：Pimpri1", "经验：5年", "手机号：9898989898", "600"},
                    {"医生姓名：Prasad Pawar", "医院地址：Migdi", "经验：15年", "手机号：7898989898", "988"},
                    {"医生姓名：SMapnil Kale", "医院地址：Pune", "经验：8年", "手机号：8898989898", "3008"},
                    {"医生姓名：Deepak Deshmukh", "医院地址：Chinchwad", "经验：6年", "手机号：98980000", "500"},
                    {"医生姓名：Ashok Panda", "医院地址：Katnaji", "经验：7年", "手机号：7798989898", "808"}
            };

    private String[][] doctor_details2 =
            {
                    {"医生姓名：MeeLam Pati", "医院地址：Pimpri", "经验：5年", "手机号：9898989898", "600"},
                    {"医生姓名：Swati Pawan", "医院地址：Migdi", "经验：15年", "手机号：7898989898", "900"},
                    {"医生姓名：Leenaia Kale", "医院地址：Pune", "经验：8年", "手机号：8898989898", "300"},
                    {"医生姓名：Mayuni Deshmuki", "医院地址：Chinchwad", "经验：6年", "手机号：989800000", "500"},
                    {"医生姓名：Minakshi Panda", "医院地址：Katnai", "经验：7年", "手机号：7798989898", "800"},
                    {"医生姓名：MeeLam Pati", "医院地址：Pimpri", "经验：5年", "手机号：9898989898", "600"},
                    {"医生姓名：Swati Pawan", "医院地址：Migdi", "经验：15年", "手机号：7898989898", "900"},
                    {"医生姓名：Leenaia Kale", "医院地址：Pune", "经验：8年", "手机号：8898989898", "300"},
                    {"医生姓名：Mayuni Deshmuki", "医院地址：Chinchwad", "经验：6年", "手机号：989800000", "500"},
                    {"医生姓名：Minakshi Panda", "医院地址：Katnai", "经验：7年", "手机号：7798989898", "800"},
                    {"医生姓名：MeeLam Pati", "医院地址：Pimpri", "经验：5年", "手机号：9898989898", "600"},
                    {"医生姓名：Swati Pawan", "医院地址：Migdi", "经验：15年", "手机号：7898989898", "900"},
                    {"医生姓名：Leenaia Kale", "医院地址：Pune", "经验：8年", "手机号：8898989898", "300"},
                    {"医生姓名：Mayuni Deshmuki", "医院地址：Chinchwad", "经验：6年", "手机号：989800000", "500"},
                    {"医生姓名：Minakshi Panda", "医院地址：Katnai", "经验：7年", "手机号：7798989898", "800"}
            };

    private String[][] doctor_details3 =
            {
                    {"医生姓名：Seema Patil", "医院地址：Pimpri1", "经验：4年", "手机号：9898989898", "280"},
                    {"医生姓名：Pnkaij Panab", "医院地址：Nigdi", "经验：5年", "手机号：7898989898", "300"},
                    {"医生姓名：Monish Jain", "医院地址：Pune", "经验：7年", "手机号：8898989898", "300"},
                    {"医生姓名：Vishal Deshmukh", "医院地址：Chinchwad", "经验：6年", "手机号：989800000", "500"},
                    {"医生姓名：Shnikant Panda", "医院地址：Katnai", "经验：7年", "手机号：7798989898", "60"}
            };

    private String[][] doctor_details4 =
            {
                    {"医生姓名：Amal Gawade", "医院地址：Pimpri", "经验：5年", "手机号：9898989898", "600"},
                    {"医生姓名：Prasad Paa", "医院地址：Nigdi", "经验：15年", "手机号：7898989898", "980"},
                    {"医生姓名：Nilesh Kale", "医院地址：Pune", "经验：8年", "手机号：8898989898", "300"},
                    {"医生姓名：Deepak Deshpande", "医院地址：Chinchwad", "经验：6年", "手机号：9898000000", "500"},
                    {"医生姓名：Ashok Singh", "医院地址：Katnaij", "经验：7年", "手机号：7798989898", "300"}
            };

    private String[][] doctor_details5 =
            {
                    {"医生姓名：Nilesh Bonate", "医院地址：Pimpri", "经验：5年", "手机号：9898989898", "1600"},
                    {"医生姓名：Pamkai Paarc", "医院地址：Migdi", "经验：15年", "手机号：7898989898", "1900"},
                    {"医生姓名：Sapnil LeLe", "医院地址：Pune", "经验：8年", "手机号：898989898", "1300"},
                    {"医生姓名：Deepak Kumar", "医院地址：Chinchwad", "经验：6年", "手机号：989800800", "1500"},
                    {"医生姓名：Ankul Panda", "医院地址：Katnaj", "经验：7年", "手机号：7798989898", "1800"}
            };



    TextView tv;
    Button btn;
    String[][] doctor_details = {};

    ArrayList list;
    SimpleAdapter sa;
    HashMap<String, String> item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_doctor_details);

        tv = findViewById(R.id.titleViewDDTitle);
        btn = findViewById(R.id.buttonDDBack);
        Intent it = getIntent();
        String title = it.getStringExtra("title");
        tv.setText(title);

        if (title.compareTo("内科医生") == 0) {
            doctor_details = doctor_details1;
        } else if (title.compareTo("营养师") == 0) {
            doctor_details = doctor_details2;
        } else if (title.compareTo("牙医") == 0) {
            doctor_details = doctor_details3;
        } else if (title.compareTo("外科医生") == 0) {
            doctor_details = doctor_details4;
        } else if (title.compareTo("心脏病医生") == 0) {
            doctor_details = doctor_details5;
        }

        // 返回上一个页面
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(DoctorDetailsActivity.this, FindDoctorActivity.class));
            }
        });


        list = new ArrayList();
        for (int i = 0; i < doctor_details.length; i++) {
            item = new HashMap<>();
            item.put("line1", doctor_details[i][0]);
            item.put("line2", doctor_details[i][1]);
            item.put("line3", doctor_details[i][2]);
            item.put("line4", doctor_details[i][3]);
            item.put("line5", "咨询费用:" + doctor_details[i][4] + "/-");
            list.add(item);
        }
        sa = new SimpleAdapter(this,
                list,
                R.layout.multi_lines,
                new String[]{"line1", "line2", "line3", "line4", "line5"},
                new int[]{R.id.line_a, R.id.line_b, R.id.line_c, R.id.line_d, R.id.line_e}
        );
        ListView listView = findViewById(R.id.listViewDD);
        listView.setAdapter(sa);

        // 点击某一个行跳转到某个医生的详情页面
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // 根据冒号分割字符串
                String[] parts = doctor_details[position][0].split("：");
                String englishName = parts[1].trim();
                Intent it = new Intent(DoctorDetailsActivity.this, BookAppointmentActivity.class);
                it.putExtra("text1", title);
                it.putExtra("text2", doctor_details[position][0]);
                it.putExtra("text3", doctor_details[position][1]);
                it.putExtra("text4", doctor_details[position][3]);
                it.putExtra("text5", doctor_details[position][4]);
                it.putExtra("doctorname",parts[1]);
                it.putExtra("description",doctor_details[position][1]+
                        ","+doctor_details[position][2]+","+doctor_details[position][3]+";");
                startActivity(it);
            }
        });
    }
}